﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using UnliQ.Service.Contracts;

namespace UnliQ.ServiceLayer
{
    public class QueueService : IQueueService
    {

        public QueueService()
        {

        }

        public Response<List<EventDTO>> GetAllEvents()
        {

            return new Response<List<EventDTO>>
            {
                ReturnModel = UnliQContext.Current.QueueRepo.GetList(),
                IsSuccessful = true
            };

        }

        public Response<EventDTO> GetEventDetails(EventDTO queue)
        {
            throw new NotImplementedException();
        }


        public Response<int> Insert(EventDTO eventObj)
        {      
            return new Response<int>
            {
                ReturnModel = UnliQContext.Current.QueueRepo.Insert(eventObj),
                IsSuccessful = true
            };
        }


        public Response<bool> AddInitValues(IList<EventDTO> events, IList<EventDateDTO> eventDates, IList<RecurringDTO> recurring, IList<EventRecurringDTO> eventsRecurring, IList<EventDateSequenceDTO> eventDateSequence, IList<EventTriggerDTO> eventTrigger)
        {

            UnliQContext.Current.QueueRepo.AddInitValues(events, eventDates, recurring, eventsRecurring, eventDateSequence, eventTrigger);

            return new Response<bool>
            {
                IsSuccessful = true,
                ReturnModel = true
            };
        }


        public Response Update(EventDTO eventObj)
        {
            UnliQContext.Current.QueueRepo.Update(eventObj);

            return new Response
            {                
                IsSuccessful = true
            };
        }


        public Response Delete(int Id)
        {
            UnliQContext.Current.QueueRepo.Delete(Id);

            return new Response
            {
                IsSuccessful = true
            };
        }

        public Response<EventDTO> GetEvent(int Id)
        {
            return new Response<EventDTO>
            {
                ReturnModel = UnliQContext.Current.QueueRepo.Get(Id),
                IsSuccessful = true
            };
        }


        public Response<int> AssignUserToQueue(int userId, string eventName = "", int eventId = 0)
        {
            return new Response<int>
            {
                ReturnModel = UnliQContext.Current.QueueRepo.AssignUserToQueue(userId, eventName, eventId),
                IsSuccessful = true
            };
        }

        public Response RemoveUserFromQueue(int userId, string eventName = "", int eventId = 0)
        {
            UnliQContext.Current.QueueRepo.RemoveUserFromQueue(userId, eventName, eventId);

            return new Response
            {
                IsSuccessful = true
            };
        }


        public Response<List<EventDTO>> GetActiveList()
        {
            return new Response<List<EventDTO>>
            {
                ReturnModel = UnliQContext.Current.QueueRepo.GetListActive(),
                IsSuccessful = true
            };
        }


        public Response<List<EventDTO>> GetUserEvents(int userId)
        {
            return new Response<List<EventDTO>>
            {
                ReturnModel = UnliQContext.Current.QueueRepo.GetUserEvents(userId),
                IsSuccessful = true
            };
        }


        public Response<List<int>> GetUsersInEvent(string eventName = "", int eventId = 0)
        {
            return new Response<List<int>>
            {
                ReturnModel = UnliQContext.Current.QueueRepo.GetUsersInEvent(eventName, eventId),
                IsSuccessful = true
            };
        }


        public Response<int> GetCurrentQueue(string eventName = "", int eventId = 0)
        {
            return new Response<int>
            {
                ReturnModel = UnliQContext.Current.QueueRepo.GetCurrentQueue(eventName, eventId),
                IsSuccessful = true
            };
        }


        public Response<int> NextQueue(string eventName = "", int eventId = 0)
        {            
            return new Response<int>
            {
                ReturnModel = UnliQContext.Current.QueueRepo.NextQueue(eventName, eventId),
                IsSuccessful = true
            };
        }



        public Response<List<EventDTO>> GetUserTriggeredEvents(int userId)
        {
            return new Response<List<EventDTO>>
            {
                ReturnModel = UnliQContext.Current.QueueRepo.GetUserTriggeredEvents(userId),
                IsSuccessful = true
            };
        }
    }
}
